package org.example.review.constants;

/**
 * 工作状态常量定义
 * 基于Apply实体的状态设计
 */
public class WorkStatus {

    // ===== 差旅申请相关状态 =====
    public static final int TRAVEL_DRAFT = 0;              // 差旅申请草稿
    public static final int TRAVEL_REJECTED = 1;           // 差旅申请未通过
    public static final int TRAVEL_REVIEWING = 2;          // 差旅申请审核中
    // 注意：状态3被预支付款占用，差旅申请通过后可能直接跳转到状态4

    // ===== 预支付款相关状态 =====
    public static final int ADVANCE_REVIEWING = 3;         // 预支付款审核中
    public static final int ADVANCE_APPROVED = 4;          // 预支付款审核通过
    // 缺少预支付款已拒绝状态（当前设计中使用TRAVEL_REJECTED）

    // ===== 报销相关状态 =====
    public static final int REIMBURSE_REJECTED = 5;        // 报销申请未通过
    public static final int REIMBURSE_REVIEWING = 6;       // 报销申请审核中
    public static final int PAYMENT_REVIEWING = 7;         // 报销支付审核中

    // ===== 最终状态 =====
    public static final int COMPLETED = 8;                 // 已完成

    // ===== API返回状态 =====
    public static final String API_STATUS_PENDING = "pending";
    public static final String API_STATUS_APPROVED = "approved";
    public static final String API_STATUS_REJECTED = "rejected";

    // ===== 业务阶段 =====
    public static final String STAGE_TRAVEL = "travel";      // 差旅申请阶段
    public static final String STAGE_ADVANCE = "advance";    // 预支付款阶段
    public static final String STAGE_REIMBURSE = "reimburse"; // 报销阶段

    /**
     * 获取API状态字符串
     */
    public static String getApiStatus(int dbStatus) {
        switch (dbStatus) {
            case 0:
            case 1:
            case 5:
                return API_STATUS_REJECTED; // 草稿/未通过 -> rejected
            case 2:
            case 3:
            case 6:
            case 7:
                return API_STATUS_PENDING; // 审核中 -> pending
            case 4:
            case 8:
                return API_STATUS_APPROVED; // 已通过/完成 -> approved
            default:
                return API_STATUS_PENDING;
        }
    }

    /**
     * 获取业务阶段
     */
    public static String getBusinessStage(int dbStatus) {
        if (dbStatus <= 2) {
            return STAGE_TRAVEL;
        } else if (dbStatus <= 4) {
            return STAGE_ADVANCE;
        } else {
            return STAGE_REIMBURSE;
        }
    }

    /**
     * 判断是否为审核中状态
     */
    public static boolean isReviewing(int status) {
        return status == TRAVEL_REVIEWING ||
               status == ADVANCE_REVIEWING ||
               status == REIMBURSE_REVIEWING ||
               status == PAYMENT_REVIEWING;
    }

    /**
     * 获取状态描述
     */
    public static String getStatusDescription(int status) {
        switch (status) {
            case TRAVEL_DRAFT: return "差旅申请草稿";
            case TRAVEL_REJECTED: return "差旅申请未通过";
            case TRAVEL_REVIEWING: return "差旅申请审核中";
            case ADVANCE_REVIEWING: return "预支付款审核中";
            case ADVANCE_APPROVED: return "预支付款审核通过";
            case REIMBURSE_REJECTED: return "报销申请未通过";
            case REIMBURSE_REVIEWING: return "报销申请审核中";
            case PAYMENT_REVIEWING: return "报销支付审核中";
            case COMPLETED: return "已完成";
            default: return "未知状态";
        }
    }
}